package routes

import (
	"github.com/gin-gonic/gin"
	"zbn-oil-consumption/controllers"
	"zbn-oil-consumption/middleware"
)

func SetupRouter(r *gin.Engine) *gin.Engine {

	r.Static("/web", "./web")
	r.Use(middleware.CorsHandler())
	cUser := controllers.User{}
	cAdmin := controllers.Admin{}
	cCar := controllers.Car{}
	cRecord := controllers.Record{}

	api := r.Group("/api/v1")
	{
		api.POST("/user/login", cUser.Login)
		api.POST("/user/register", cUser.Register)
	}
	apiAuth := r.Group("/api/v1", middleware.Auth())
	{
		apiAuth.GET("/user/info", cUser.GetUserInfo)
		apiAuth.GET("/car/index", cCar.Index)
		apiAuth.GET("/car/info", cCar.Info)
		apiAuth.POST("/car/save", cCar.Save)
		apiAuth.POST("/record/save", cRecord.Save)
		apiAuth.GET("/record/list", cRecord.List)
		apiAuth.GET("/record/detail", cRecord.Detail)
		apiAuth.GET("/record/statistics", cRecord.Statistics)

	}
	// 管理后台API
	admin := r.Group("/admin")
	{
		admin.POST("/login", cAdmin.Login)
	}
	adminAuth := r.Group("/admin")
	{
		adminAuth.GET("/user/list", cAdmin.UserList)
		adminAuth.POST("/user/save", cAdmin.UserSave)
		adminAuth.POST("/user/delete", cAdmin.UserDelete)
		adminAuth.POST("/user/changeStatus", cAdmin.UserChangeStatus)

		adminAuth.GET("/record/list", cAdmin.RecordList)
		adminAuth.GET("/record/chart", cAdmin.Chart)
		adminAuth.GET("/car/list", cCar.List)

		adminAuth.GET("/admin/list", cAdmin.AdminList)
		adminAuth.POST("/admin/save", cAdmin.AdminSave)
		adminAuth.POST("/admin/update", cAdmin.AdminUpdate)
		adminAuth.POST("/admin/delete", cAdmin.AdminDelete)
		adminAuth.POST("/admin/changeStatus", cAdmin.AdminChangeStatus)

	}

	return r
}
